package com.example.behaviordemo.adapter

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.behaviordemo.model.Dynamic
import androidx.recyclerview.widget.RecyclerView.ViewHolder

import android.view.LayoutInflater
import android.widget.TextView
import com.example.behaviordemo.R

/**
 * author : king_nina
 * e-mail : 13450414852@163.com
 * date   : 2021/12/2
 * desc   :
 */
class DynamicAdapter : RecyclerView.Adapter<DynamicAdapter.DynamicViewHolder> {

    private var dynamics = mutableListOf<Dynamic>()

    constructor(datas: List<Dynamic>) {
        dynamics.addAll(datas)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DynamicViewHolder {
        val view: View =
            LayoutInflater.from(parent.context).inflate(R.layout.item_dynamic, parent, false)
        return DynamicViewHolder(view)
    }

    override fun onBindViewHolder(holder: DynamicViewHolder, position: Int) {
        val dynamic = dynamics[position]
        holder.tvTitle.text = dynamic.artTitle
        holder.tvContent.text = dynamic.artContent
        holder.tvCategory.text = dynamic.artCategory
    }

    override fun getItemCount(): Int {
        return dynamics.size
    }

    class DynamicViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var tvTitle: TextView = itemView.findViewById(R.id.tvTitle)
        var tvContent: TextView = itemView.findViewById(R.id.tvContent)
        var tvCategory: TextView = itemView.findViewById(R.id.tvCategory)

    }
}